import  matplotlib.pyplot as plt
import pandas as pd
#读取数据
# data=pd.read_csv('GSW_players_stats_2017_18.csv')
#
# #将其按照字段Pos进行分组
# data_groupby=data.groupby('Pos')
# position=data_groupby['Pos'].count()

#垂直条形图画图
# plt.bar([1,2,3,4,5],position)
# plt.xticks([1,2,3,4,5],position.index)
# plt.ylabel('Number of people')
# plt.xlabel('Position')
# plt.title('NBA Golden State Warriors')
# # plt.show()

#水平条形图画图
# plt.barh([1,2,3,4,5],position)
# plt.yticks([1,2,3,4,5],position.index)
# plt.xlabel('Number of people')
# plt.ylabel('Position')
# plt.title('NBA Golden State Warriors')
# plt.show()

#-----------------------------------------------------------------------------------------------------------------------
#绘制两个数据集的条形图
# df=pd.read_csv('HOU_players_stats_2017_18.csv')
# df_grouped=df.groupby('Pos')
# #求均值
# points=df_grouped['PTS/G'].mean()
# rebounds=df_grouped['TRB'].mean()

# plt.bar([1,2,3,4,5],points,label='Points')
# plt.bar([1,2,3,4,5],rebounds,label='Rebounds')
# plt.xticks([1,2,3,4,5],points.index)
# plt.legend()
# plt.ylabel('Points and Rebounds')
# plt.xlabel('Position')
# plt.title('NBA Honston Rockets')
# plt.show()

#并排显示数据集
# index=range(1,11)
# plt.bar(index[0::2],points,label='Points')
# plt.bar(index[1::2],rebounds,label='Rebounds')
# plt.xticks(index[0::2],points.index)
# plt.legend()
# plt.ylabel('Points and Rebounds')
# plt.xlabel('Position')
# plt.title('NBA Honston Rockets')
# plt.show()

#-----------------------------------------------------------------------------------------------------------------------
#绘制直方图
# x=[21,42,4,5,26,77,88,9,10,31,32,33,34,35,36,37,18,49,50,100]
# num_bins=5
# n,bins,patches=plt.hist(x,num_bins)
# print(n)
# print(bins)
# plt.show()

#显示NBA球员的年薪分布的直方图
# df=pd.read_csv('NBA_salary_rankings_2018.csv')
# num_bins=15
# plt.hist(df['salary'],num_bins)
# plt.ylabel('Frequency')
# plt.xlabel('Salary')
# plt.title('Histogram  of NBA Top 100 Salary')
# plt.show()

#-----------------------------------------------------------------------------------------------------------------------
#绘制箱线图
#NBA前100名球员依位置年薪分布的箱线图
# df=pd.read_csv('NBA_salary_rankings_2018.csv')
# df=df.sort_values('pos')#排序
# col=df.drop_duplicates(['pos'])#去重
#
# data=[]
# #col['pos'].values则是取出5个位置的字符串列表，然后创建个位置薪水的嵌套列表。
# # 使用条件df.pos==pos过滤出此位置的年薪数据，
# for pos in col['pos'].values:
#     d=df[(df.pos==pos)]
#     data.append(df['salary'].values)
#
# plt.boxplot(data)
# plt.xticks(range(1,6),col['pos'],rotation=25)
# plt.title('Box Plot of NBA Salary')
# plt.show()

#-----------------------------------------------------------------------------------------------------------------------
#绘制散点图
# df=pd.read_csv('NBA_players_salary_stats_2018.csv')
# plt.scatter(df['PTS'],df['salary'])
# plt.ylabel('Salary')
# plt.xlabel('PTS')
# plt.title('Scatter Plot of NBA Salary and PTS')
# plt.show()

#-----------------------------------------------------------------------------------------------------------------------
#绘制饼图,使用突增值表示饼图的切片,并显示图列
# df=pd.read_csv('GSW_players_stats_2017_18.csv')
# df_grouded=df.groupby('Pos')
# position=df_grouded['Pos'].count()
# explode=(0,0,0.2,0,0.2)
# patches,texts=plt.pie(position,labels=position.index,explode=explode)
# plt.legend(patches,position.index,loc='best')
# plt.axis('equal')
# plt.title('NBA Golend State Warriors')
# plt.show()

#-----------------------------------------------------------------------------------------------------------------------
#折线图
#显示的得分、助攻、篮板的折线图
# df=pd.read_csv('Kobe_stats.csv')
#
# df['Season']=pd.to_datetime(df['Season'])
# df=df.set_index('Season')
# plt.plot(df['PTS'],'r--o',label='PTS')
# plt.plot(df['AST'],'b--o',label='AST')
# plt.plot(df['TRB'],'g--o',label='REB')
# plt.legend()
# plt.ylabel('Stats')
# plt.xlabel('Season')
# plt.title('Kobe Bryant')
# plt.show()

#-----------------------------------------------------------------------------------------------------------------------
#matplotlib 的轴与子图表
import math
x=[0,0.5,1,1.5,2,2.5,3,3.5,4,4.5,5,5.5,6,6.5,7.5]
sinus=[math.sin(v) for v in x]
cos=[math.cos(v) for v in x]
plt.subplot(1,2,1)
plt.plot(x,sinus,'r--o')
plt.subplot(1,2,2)
plt.plot(x,cos,'g--o')
plt.show()